<%@ page contentType="text/html; charset=UTF-8" %>
<%
String webpath = request.getContextPath();
Runtime run = Runtime.getRuntime();
long t = run.totalMemory()/1024/1024;
long fr = run.freeMemory()/1024/1024;
long max = run.maxMemory()/1024/1024;
long rem = t - fr;
StringBuilder sb=new StringBuilder();
sb.append("最大:" + max + " MB ,").append("已分配:" + t + " MB ,")
.append("实际占用:" + rem + " MB ,").append("剩余:" + fr + " MB ");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>监控应用信息</title>
<style type="text/css">
<!--
body,table{font-size:12px;}
table{table-layout:fixed;empty-cells:show;border-collapse: collapse;margin:0 auto;}
td{height:20px;}
h1,h2,h3{font-size:12px;margin:0;padding:0;}
table.t1{border:1px solid #cad9ea;color:#666;}
table.t1 th {background-color:#f5fafe;height:20px;}
table.t1 td,table.t1 th{border:1px solid #cad9ea;padding:0 1em 0;}
table.t1 tr.a1{background-color:#f5fafe;}
-->
</style>
</head>
<body>
<p><button onclick="window.location.reload()">刷新</button></p>
<p>WEB应用信息：</p>
<table width="100%" id="mytab"  border="1" class="t1">
	<tr>
		<th width="20%">应用名</th>
		<td width="30%"><%=request.getContextPath()%></td>
		<th width="20%">应用端口</th>
		<td width="30%"><%=request.getServerPort()%>,<%=request.getLocalPort()%>,<%=request.getLocalAddr()%></td>
	</tr>
	<tr>
		<th>JVM内存</th>
		<td colspan="3"><%=sb.toString()%></td>
	</tr>
	<tr>
		<th>应用真实路径</th>
		<td colspan="3"><%=session.getServletContext().getRealPath("")%></td>
	</tr>
	<tr>
		<th>ServerInfo</th>
		<td><%=session.getServletContext().getServerInfo()%></td>
		<th>ServletVersion</th>
		<td><%=session.getServletContext().getMajorVersion()%>.<%=session.getServletContext().getMinorVersion()%></td>
	</tr>
	<tr>
		<th>ServletContextName</th>
		<td><%=session.getServletContext().getServletContextName()%></td>
		<th>os.arch</th>
		<td><%=System.getProperty("os.arch")%></td>
	</tr>
	<tr>
		<th>os.name</th>
		<td><%=System.getProperty("os.name")%></td>
		<th>os.version</th>
		<td><%=System.getProperty("os.version")%></td>
	</tr>
	<tr>
		<th>user.home</th>
		<td><%=System.getProperty("user.home")%></td>
		<th>user.name</th>
		<td><%=System.getProperty("user.name")%></td>
	</tr>
	<tr>
		<th>user.dir</th>
		<td colspan="3"><%=System.getProperty("user.dir")%></td>
	</tr>
	<tr>
		<th>user.language</th>
		<td><%=System.getProperty("user.language")%></td>
		<th>user.timezone</th>
		<td><%=System.getProperty("user.timezone")%></td>
	</tr>
	<tr>
		<th>java.library.path</th>
		<td colspan="3"><%=System.getProperty("java.library.path")%></td>
	</tr>
	<tr>
		<th>java.home</th>
		<td><%=System.getProperty("java.home")%></td>
		<th>java.vendor</th>
		<td><%=System.getProperty("java.vendor")%></td>
	</tr>
	<tr>
		<th>java.version</th>
		<td><%=System.getProperty("java.version")%></td>
		<th>java.vm.info</th>
		<td><%=System.getProperty("java.vm.info")%></td>
	</tr>
	<tr>
		<th>java.vm.name</th>
		<td><%=System.getProperty("java.vm.name")%></td>
		<th>java.vm.vendor</th>
		<td><%=System.getProperty("java.vm.vendor")%></td>
	</tr>
	<tr>
		<th>java.vm.version</th>
		<td><%=System.getProperty("java.vm.version")%></td>
		<th>java.io.tmpdir</th>
		<td><%=System.getProperty("java.io.tmpdir")%></td>
	</tr>
</table>
<p>Server线程信息：</p>
<table width="100%" id="thread"  border="1" class="t1">
	<tr>
		<th width="25%">线程名</th>
		<th width="15%">状态</th>
		<th width="60%">线程类</th>
	</tr>
<%for(Thread thread : list_threads()){%>
	<tr>
		<td><%=thread.getName()%></td>
		<td><%=thread.getState()%></td>
		<td><%=thread.getClass().getName()%></td>
	</tr>
<%}%>
</table>
</body>
</html>
<%!
public static java.util.List<Thread> list_threads(){
    int tc = Thread.activeCount();
    Thread[] ts = new Thread[tc];
    Thread.enumerate(ts);
    return java.util.Arrays.asList(ts);
}
%>

